home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Color Matching Method (CMM) Component Shell
-
- 93.06.26 tem Fix version returned by ComponentVersion(…)
- Rework ComponentCanDo(…)
-
- */
-
- #include <QuickDraw.h>
- #include <Components.h>
- #include <CMComponent.h>
- #include <CMApplication.h>
- #include <Memory.h>
-
- /* Prototypes of CMS component routines */
-
- pascal CMError ComponentOpen(Handle storage, ComponentInstance self);
- pascal CMError ComponentClose(Handle storage, ComponentInstance self);
- pascal long ComponentCanDo(Handle storage, short selector);
- pascal long ComponentVersion(Handle storage);
- pascal CMError CMMInit( Handle storage, CMProfileHandle srcProfile, CMProfileHandle dstProfile);
- pascal CMError CMMMatchColors( Handle storage, CMColorList myColors, long count );
- pascal CMError CMMGamutTest( Handle storage, CMColorList myColors, long count, CMGamutResult result );
-
-
-
- #define CMCodeVersion 1
-
- /* Build a code resource */
- #define realthing
-
- #ifdef realthing
- pascal ComponentResult main( ComponentParameters *params, Handle storage )
- #else
- pascal ComponentResult CMM( ComponentParameters *params, Handle storage )
- #endif
- {
- ComponentFunction routineToCall = 0;
- short message = params->what;
- CMError result;
-
- if (message < 0) {
- switch (message) {
- case kComponentOpenSelect : routineToCall = (ComponentFunction)ComponentOpen;
- break;
- case kComponentCloseSelect : routineToCall = (ComponentFunction)ComponentClose;
- break;
- case kComponentCanDoSelect : routineToCall = (ComponentFunction)ComponentCanDo;
- break;
- case kComponentVersionSelect : routineToCall = (ComponentFunction)ComponentVersion;
- default : return (noErr);
- }
- }
- else {
- switch (message) {
- case kCMInit : routineToCall = (ComponentFunction)CMMInit;
- break;
- case kCMMatchColors : routineToCall = (ComponentFunction)CMMMatchColors;
- break;
- case kCMGamutTest : routineToCall = (ComponentFunction)CMMGamutTest;
- break;
- default : return (CMUnimplementedError);
- }
- };
-
- result = CallComponentFunctionWithStorage(storage, params, routineToCall);
-
- return result;
- }
-
- pascal CMError ComponentOpen(Handle storage, ComponentInstance self)
- {
- Handle myStorage; /* allocate dummy handle for private storage */
-
- myStorage = (Handle) NewHandle( sizeof( long ) );
- SetComponentInstanceStorage( self, myStorage );
- return( noErr );
- }
-
- /* This is the DisposeMatchData call -- Clean up private storage */
- pascal CMError ComponentClose(Handle storage, ComponentInstance self)
- {
- DisposHandle( storage );
- return( noErr );
- }
-
- pascal long ComponentCanDo(Handle storage, short selector)
- {
- long result;
-
- switch (selector)
- {
- /* Component Manager selectors */
- case kComponentOpenSelect:
- case kComponentCloseSelect:
- case kComponentCanDoSelect:
- case kComponentVersionSelect:
- result = true;
- break;
- case kComponentRegisterSelect:
- case kComponentTargetSelect:
- result = false;
- break;
-
- /* CMM Component selectors */
- case kCMInit:
- case kCMMatchColors:
- case kCMGamutTest:
- result = true;
- break;
-
- case kCMMatchPixMap:
- case kCMCheckPixMap:
- case kCMConcatenateProfiles:
- result = false;
- break;
-
- default:
- result = false;
- break;
- }
-
- return (result);
- }
-
- pascal long ComponentVersion(Handle storage)
- {
- /* interface version in hi word, */
- /* code rev in lo word */
- return(((CMInterfaceVersion << 16) | CMCodeVersion));
- }
-
- pascal CMError CMMInit( Handle storage, CMProfileHandle src, CMProfileHandle dst )
- {
- /* Do something intelligent here, like fill out storage with conversion info */
-
- if( (**dst).header.size == sizeof(CMHeader) )
- **storage = 0L;
- else
- **storage = 0xffffffffL; /* flag matching should occur */
-
- return( noErr );
- }
-
-
- pascal CMError CMMMatchColors( Handle storage, CMColorList myColors, long count )
- {
- long iii;
- CMError error;
- long index;
- RGBColor *myColorPtr; /* A real CMM would use CMColor* */
-
- if( **storage ) /* only match if flagged */
- {
- for (iii=0; iii<count; iii++)
- {
- myColorPtr = (RGBColor *)(((char *)myColors) + (iii<<3));
-
- /* Just invert the RGB components */
- (*myColorPtr).red = ~(*myColorPtr).red;
- (*myColorPtr).green = ~(*myColorPtr).green;
- (*myColorPtr).blue = ~(*myColorPtr).blue;
- }
- }
-
- return( noErr );
- }
-
-
- pascal CMError CMMGamutTest( Handle storage, CMColorList myColors, long count, CMGamutResult result )
- {
- unsigned long mask;
- long dstLong;
- long iii;
- RGBColor *myColorPtr; /* A real CMM would use CMColor* */
-
- /* Fill out CMGamutResult bit-field. */
-
- mask = 0x80000000;
- dstLong = 0;
- for (iii=0; iii<count; iii++)
- {
- myColorPtr = (RGBColor *)(((char *)myColors) + (iii<<3));
-
- if( (*myColorPtr).red >= 0x8000 )
- {
- dstLong |= mask;
- }
- mask >>= 1;
- if( !mask )
- {
- mask = 0x80000000;
- *result++ = dstLong;
- dstLong = 0;
- }
- }
- if (mask != 0x80000000)
- *result = dstLong;
-
- return( noErr );
- }
-
-
-